<template>
  <div class="home">
    <ul>
      <li v-for="(item, index) in $store.state.unreadList" :key="index">
        {{ item }}
        <el-button type="warning" size="small" @click="jump(index)"
          >标记已读</el-button
        >
      </li>
    </ul>
    <el-button @click="alladd">全部</el-button>
  </div>
</template>

<script>
// @ is an alias to /src

export default {
  name: "Home",
  data() {
    return {};
  },
  created() {
    if (!localStorage.getItem("vuex")) {
      this.$axios.get("list.json").then((res) => {
        // this.$store.commit("sendList", { style: "unread", list: res.data });
        this.$store.state.unreadList = res.data;
        // console.log('fghjkl');
      });
    }
  },
  methods: {
    jump(i) {
      this.$store.commit("sendList", { style: "unread", index: i });
    },
    alladd(){
      this.$store.commit("allList", 'unread');
    }
  },
};
</script>

